/*     */ package com.zimbra.cs.mailbox;
/*     */ 
/*     */ import com.zimbra.common.calendar.ICalTimeZone;
/*     */ import com.zimbra.common.calendar.ParsedDateTime;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.util.DateTimeUtil;
/*     */ import com.zimbra.common.util.L10nUtil;
/*     */ import com.zimbra.common.util.L10nUtil.MsgKey;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.CalendarResource;
/*     */ import com.zimbra.cs.fb.FreeBusy;
/*     */ import com.zimbra.cs.fb.FreeBusy.FBInstance;
/*     */ import com.zimbra.cs.fb.FreeBusy.Interval;
/*     */ import com.zimbra.cs.mailbox.calendar.CalendarMailSender;
/*     */ import com.zimbra.cs.mailbox.calendar.CalendarMailSender.Verb;
/*     */ import com.zimbra.cs.mailbox.calendar.Invite;
/*     */ import com.zimbra.cs.mailbox.calendar.InviteInfo;
/*     */ import com.zimbra.cs.mailbox.calendar.RecurId;
/*     */ import com.zimbra.cs.mailbox.calendar.Util;
/*     */ import com.zimbra.cs.mailbox.calendar.ZAttendee;
/*     */ import com.zimbra.cs.mailbox.calendar.ZOrganizer;
/*     */ import com.zimbra.cs.redolog.RedoLogManager;
/*     */ import com.zimbra.cs.redolog.RedoLogProvider;
/*     */ import com.zimbra.cs.redolog.op.CreateCalendarItemPlayer;
/*     */ import com.zimbra.cs.redolog.op.CreateCalendarItemRecorder;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Collection;
/*     */ import java.util.Date;
/*     */ import java.util.Iterator;
/*     */ import java.util.List;
/*     */ import java.util.Locale;
/*     */ import java.util.TimeZone;
/*     */ import javax.mail.internet.MimeMessage;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class Appointment
/*     */   extends CalendarItem
/*     */ {
/*     */   private static final int TWENTY_FIVE_HOURS = 90000000;
/*     */   private static final int TWO_HOURS = 7200000;
/*     */   private static final int MIN_CONFLICT_LIST_SIZE = 5;
/*     */   
/*     */   public Appointment(Mailbox mbox, MailItem.UnderlyingData data)
/*     */     throws ServiceException
/*     */   {
/*  68 */     this(mbox, data, false);
/*     */   }
/*     */   
/*     */   public Appointment(Mailbox mbox, MailItem.UnderlyingData data, boolean skipCache) throws ServiceException {
/*  72 */     super(mbox, data, skipCache);
/*  73 */     if (this.mData.type != MailItem.Type.APPOINTMENT.toByte()) {
/*  74 */       throw new IllegalArgumentException();
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public String getEffectiveFreeBusyActual(Invite inv, CalendarItem.Instance inst)
/*     */     throws ServiceException
/*     */   {
/*  96 */     if (!inv.isOrganizer()) {
/*  97 */       ZAttendee at = getReplyList().getEffectiveAttendee(getMailbox().getAccount(), inv, inst);
/*  98 */       if (at != null) {
/*  99 */         if (at.hasPartStat()) {
/* 100 */           return inv.partStatToFreeBusyActual(at.getPartStat());
/*     */         }
/* 102 */         return inv.getFreeBusyActual();
/*     */       }
/*     */     }
/* 105 */     return inv.getFreeBusyActual();
/*     */   }
/*     */   
/*     */   public static class Conflict {
/*     */     private CalendarItem.Instance mInstance;
/*     */     private FreeBusy mFreeBusy;
/*     */     private String mFreeBusyStatus;
/*     */     
/*     */     public Conflict(CalendarItem.Instance inst, String fbStatus, FreeBusy fb) {
/* 114 */       this.mInstance = inst;
/* 115 */       this.mFreeBusyStatus = fbStatus;
/* 116 */       this.mFreeBusy = fb;
/*     */     }
/*     */     
/* 119 */     public CalendarItem.Instance getInstance() { return this.mInstance; }
/* 120 */     public FreeBusy getFreeBusy() { return this.mFreeBusy; }
/* 121 */     public boolean isBusy() { return isBusy(this.mFreeBusyStatus); }
/*     */     
/*     */     public static boolean isBusy(String fbStatus) {
/* 124 */       return ("B".equals(fbStatus)) || ("O".equals(fbStatus));
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   private static String getBusyTimesString(OperationContext octxt, Mailbox mbox, List<Conflict> list, TimeZone tz, Locale lc, boolean hasMoreConflicts)
/*     */     throws ServiceException
/*     */   {
/* 133 */     StringBuilder sb = new StringBuilder();
/* 134 */     int conflictCount = 0;
/* 135 */     for (Conflict avail : list)
/* 136 */       if (avail.isBusy())
/*     */       {
/*     */ 
/* 139 */         FreeBusy fb = avail.getFreeBusy();
/* 140 */         List<FreeBusy.FBInstance> instances = new ArrayList();
/* 141 */         for (Iterator<FreeBusy.Interval> iter = fb.iterator(); iter.hasNext();) {
/* 142 */           FreeBusy.Interval interval = (FreeBusy.Interval)iter.next();
/*     */           
/* 144 */           if (Conflict.isBusy(interval.getStatus()))
/*     */           {
/* 146 */             for (FreeBusy.FBInstance fbinst : interval.getInstances()) {
/* 147 */               if (Conflict.isBusy(fbinst.getFreeBusy()))
/* 148 */                 instances.add(fbinst);
/*     */             }
/*     */           }
/*     */         }
/* 152 */         for (FreeBusy.FBInstance instance : instances) {
/* 153 */           Date startDate = new Date(instance.getStartTime());
/* 154 */           Date endDate = new Date(instance.getEndTime());
/* 155 */           String start = CalendarMailSender.formatDateTime(startDate, tz, lc);
/* 156 */           sb.append(" * ").append(start);
/*     */           
/* 158 */           if (DateTimeUtil.sameDay(startDate, endDate, tz)) {
/* 159 */             String end = CalendarMailSender.formatTime(endDate, tz, lc);
/* 160 */             sb.append(" - ").append(end);
/*     */           } else {
/* 162 */             String end = CalendarMailSender.formatDateTime(endDate, tz, lc);
/* 163 */             sb.append("\r\n   - ").append(end);
/*     */           }
/*     */           
/* 166 */           int apptId = instance.getApptId();
/* 167 */           long recurIdDt = instance.getRecurIdDt();
/* 168 */           CalendarItem appt = mbox.getCalendarItemById(octxt, apptId);
/* 169 */           Invite inv = appt.getInviteForRecurId(recurIdDt);
/* 170 */           if ((inv != null) && (inv.hasOrganizer())) {
/* 171 */             ZOrganizer organizer = inv.getOrganizer();
/*     */             String orgDispName;
/* 173 */             String orgDispName; if (organizer.hasCn()) {
/* 174 */               orgDispName = organizer.getCn() + " <" + organizer.getAddress() + ">";
/*     */             } else
/* 176 */               orgDispName = organizer.getAddress();
/* 177 */             sb.append(L10nUtil.getMessage(L10nUtil.MsgKey.calendarResourceConflictScheduledBy, lc, new Object[] { orgDispName }));
/*     */           }
/* 179 */           sb.append("\r\n");
/* 180 */           conflictCount++;
/*     */         }
/*     */       }
/* 183 */     if (hasMoreConflicts)
/* 184 */       sb.append(" * ...\r\n");
/* 185 */     return sb.toString();
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   private static String getDeclinedTimesString(OperationContext octxt, Mailbox mbox, List<Conflict> conflicts, boolean allDay, TimeZone tz, Locale lc)
/*     */     throws ServiceException
/*     */   {
/* 195 */     StringBuilder sb = new StringBuilder();
/* 196 */     int conflictCount = 0;
/* 197 */     for (Conflict conflict : conflicts)
/*     */     {
/* 199 */       CalendarItem.Instance instance = conflict.getInstance();
/* 200 */       Date startDate = new Date(instance.getStart());
/* 201 */       Date endDate = new Date(instance.getEnd());
/* 202 */       if (!allDay) {
/* 203 */         String start = CalendarMailSender.formatDateTime(startDate, tz, lc);
/* 204 */         sb.append(" * ").append(start);
/* 205 */         if (DateTimeUtil.sameDay(startDate, endDate, tz)) {
/* 206 */           String end = CalendarMailSender.formatTime(endDate, tz, lc);
/* 207 */           sb.append(" - ").append(end);
/*     */         } else {
/* 209 */           String end = CalendarMailSender.formatDateTime(endDate, tz, lc);
/* 210 */           sb.append("\r\n   - ").append(end);
/*     */         }
/*     */       }
/*     */       else {
/* 214 */         String start = CalendarMailSender.formatDate(startDate, tz, lc);
/* 215 */         sb.append(" * ").append(start);
/*     */         
/* 217 */         long duration = endDate.getTime() - startDate.getTime();
/* 218 */         if (duration > 90000000L)
/*     */         {
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 224 */           endDate = new Date(instance.getEnd() - 7200000L);
/* 225 */           String end = CalendarMailSender.formatDate(endDate, tz, lc);
/* 226 */           sb.append(" - ").append(end);
/*     */         }
/*     */       }
/* 229 */       sb.append("\r\n");
/* 230 */       conflictCount++;
/*     */     }
/* 232 */     return sb.toString();
/*     */   }
/*     */   
/*     */   private static class ConflictCheckResult {
/*     */     private List<Appointment.Conflict> mConflicts;
/*     */     private boolean mTooManyConflicts;
/*     */     private boolean mHasMoreConflicts;
/*     */     
/*     */     public ConflictCheckResult(List<Appointment.Conflict> conflicts, boolean tooManyConflicts, boolean hasMoreConflicts) {
/* 241 */       this.mConflicts = conflicts;
/* 242 */       this.mTooManyConflicts = tooManyConflicts;
/* 243 */       this.mHasMoreConflicts = hasMoreConflicts;
/*     */     }
/*     */     
/* 246 */     public List<Appointment.Conflict> getConflicts() { return this.mConflicts; }
/* 247 */     public boolean tooManyConflicts() { return this.mTooManyConflicts; }
/* 248 */     public boolean hasMoreConflicts() { return this.mHasMoreConflicts; }
/*     */   }
/*     */   
/*     */ 
/*     */   private ConflictCheckResult checkAvailability(long now, Invite invite, int maxNumConflicts, int maxPctConflicts)
/*     */     throws ServiceException
/*     */   {
/*     */     long et;
/*     */     
/* 257 */     if (invite.isRecurrence())
/*     */     {
/* 259 */       long st = getStartTime();
/* 260 */       et = getEndTime();
/*     */     }
/*     */     else {
/* 263 */       ParsedDateTime dtStart = invite.getStartTime();
/* 264 */       ParsedDateTime dtEnd = invite.getEffectiveEndTime();
/* 265 */       long et; if ((dtStart != null) && (dtEnd != null)) {
/* 266 */         long st = dtStart.getUtcTime();
/* 267 */         et = dtEnd.getUtcTime();
/*     */       }
/*     */       else {
/* 270 */         return null;
/*     */       }
/*     */     }
/*     */     long et;
/* 274 */     long st = Math.max(st, now);
/* 275 */     if (et <= st) {
/* 276 */       return null;
/*     */     }
/* 278 */     OperationContext octxt = new OperationContext(getAccount());
/*     */     Collection<CalendarItem.Instance> instances;
/* 280 */     Collection<CalendarItem.Instance> instances; if (invite.isRecurrence()) {
/* 281 */       instances = expandInstances(st, et, false);
/*     */     } else {
/* 283 */       instances = new ArrayList(1);
/* 284 */       instances.add(CalendarItem.Instance.fromInvite(getId(), invite));
/*     */     }
/* 286 */     if ((instances == null) || (instances.isEmpty())) {
/* 287 */       return null;
/*     */     }
/* 289 */     int maxByPct = maxPctConflicts * instances.size() / 100;
/* 290 */     int maxConflicts = Math.min(maxNumConflicts, maxByPct);
/*     */     
/* 292 */     List<Conflict> list = new ArrayList();
/* 293 */     int numConflicts = 0;
/* 294 */     boolean hasMoreConflicts = false;
/* 295 */     for (CalendarItem.Instance inst : instances) {
/* 296 */       if (numConflicts > Math.max(maxConflicts, 4)) {
/* 297 */         hasMoreConflicts = true;
/* 298 */         break;
/*     */       }
/* 300 */       long start = inst.getStart();
/* 301 */       long end = inst.getEnd();
/*     */       
/* 303 */       FreeBusy fb = getMailbox().getFreeBusy(octxt, start, end, this);
/* 304 */       String status = fb.getBusiest();
/* 305 */       if (Conflict.isBusy(status)) {
/* 306 */         list.add(new Conflict(inst, status, fb));
/* 307 */         numConflicts++;
/*     */       }
/*     */     }
/* 310 */     return new ConflictCheckResult(list, numConflicts > maxConflicts, hasMoreConflicts);
/*     */   }
/*     */   
/*     */   protected String processPartStat(Invite invite, MimeMessage mmInv, boolean forCreate, String defaultPartStat)
/*     */     throws ServiceException
/*     */   {
/* 316 */     Mailbox mbox = getMailbox();
/* 317 */     OperationContext octxt = mbox.getOperationContext();
/* 318 */     CreateCalendarItemPlayer player = octxt != null ? (CreateCalendarItemPlayer)octxt.getPlayer() : null;
/*     */     
/* 320 */     long opTime = octxt != null ? octxt.getTimestamp() : System.currentTimeMillis();
/*     */     
/* 322 */     Account account = getMailbox().getAccount();
/* 323 */     boolean onBehalfOf = false;
/* 324 */     Account authAcct = account;
/* 325 */     if (octxt != null) {
/* 326 */       Account authuser = octxt.getAuthenticatedUser();
/* 327 */       if (authuser != null) {
/* 328 */         onBehalfOf = !account.getId().equalsIgnoreCase(authuser.getId());
/* 329 */         if (onBehalfOf)
/* 330 */           authAcct = authuser;
/*     */       }
/*     */     }
/* 333 */     boolean asAdmin = octxt != null ? octxt.isUsingAdminPrivileges() : false;
/* 334 */     boolean allowPrivateAccess = allowPrivateAccess(authAcct, asAdmin);
/*     */     
/* 336 */     String partStat = defaultPartStat;
/* 337 */     if (player != null) {
/* 338 */       String p = player.getCalendarItemPartStat();
/* 339 */       if (p != null) { partStat = p;
/*     */       }
/*     */     }
/*     */     
/*     */ 
/* 344 */     boolean rsvpRequested = true;
/* 345 */     ZAttendee attendee = invite.getMatchingAttendee(account);
/* 346 */     if (attendee != null) {
/* 347 */       Boolean rsvp = attendee.getRsvp();
/* 348 */       if (rsvp != null)
/* 349 */         rsvpRequested = rsvp.booleanValue();
/*     */     }
/* 351 */     RedoLogProvider redoProvider = RedoLogProvider.getInstance();
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 359 */     boolean needReplyEmail = (rsvpRequested) && (redoProvider.isMaster()) && ((player == null) || (redoProvider.getRedoLogManager().getInCrashRecovery())) && (invite.hasOrganizer()) && (!invite.isCancel()) && (!invite.isTodo()) && (!account.isIsSystemResource());
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 368 */     if (invite.isOrganizer())
/*     */     {
/* 370 */       partStat = "AC";
/* 371 */     } else if (((account instanceof CalendarResource)) && (octxt == null))
/*     */     {
/*     */ 
/*     */ 
/*     */ 
/* 376 */       boolean replySent = false;
/* 377 */       CalendarResource resource = (CalendarResource)account;
/*     */       
/* 379 */       Account organizer = invite.getOrganizerAccount();
/* 380 */       Locale lc; Locale lc; if (organizer != null) {
/* 381 */         lc = organizer.getLocale();
/*     */       } else
/* 383 */         lc = resource.getLocale();
/* 384 */       if ((resource.autoAcceptDecline()) || (resource.autoDeclineIfBusy()) || (resource.autoDeclineRecurring())) {
/* 385 */         boolean replyListUpdated = false;
/*     */         
/*     */ 
/* 388 */         if (resource.autoAcceptDecline())
/* 389 */           partStat = "AC";
/* 390 */         if ((isRecurring()) && (resource.autoDeclineRecurring()))
/*     */         {
/* 392 */           partStat = "DE";
/* 393 */           if (needReplyEmail) {
/* 394 */             String reason = L10nUtil.getMessage(L10nUtil.MsgKey.calendarResourceDeclineReasonRecurring, lc, new Object[0]);
/*     */             
/* 396 */             Invite replyInv = makeReplyInvite(account, authAcct, lc, onBehalfOf, allowPrivateAccess, invite, invite.getRecurId(), CalendarMailSender.VERB_DECLINE);
/*     */             
/*     */ 
/* 399 */             CalendarMailSender.sendResourceAutoReply(octxt, mbox, true, CalendarMailSender.VERB_DECLINE, false, reason + "\r\n", this, invite, new Invite[] { replyInv }, mmInv);
/*     */             
/*     */ 
/*     */ 
/*     */ 
/* 404 */             replySent = true;
/*     */           }
/* 406 */         } else if (resource.autoDeclineIfBusy())
/*     */         {
/* 408 */           int maxNumConflicts = resource.getMaxNumConflictsAllowed();
/* 409 */           int maxPctConflicts = resource.getMaxPercentConflictsAllowed();
/* 410 */           ConflictCheckResult checkResult = checkAvailability(opTime, invite, maxNumConflicts, maxPctConflicts);
/* 411 */           if (checkResult != null) {
/* 412 */             List<Conflict> conflicts = checkResult.getConflicts();
/* 413 */             if (conflicts.size() > 0) {
/* 414 */               if ((invite.isRecurrence()) && (!checkResult.tooManyConflicts()))
/*     */               {
/* 416 */                 if (resource.autoAcceptDecline())
/*     */                 {
/* 418 */                   List<Invite> replyInvites = new ArrayList();
/*     */                   
/* 420 */                   Invite acceptInv = makeReplyInvite(account, authAcct, lc, onBehalfOf, allowPrivateAccess, invite, invite.getRecurId(), CalendarMailSender.VERB_ACCEPT);
/*     */                   
/*     */ 
/*     */ 
/* 424 */                   for (Conflict conflict : conflicts) {
/* 425 */                     CalendarItem.Instance inst = conflict.getInstance();
/* 426 */                     InviteInfo invInfo = inst.getInviteInfo();
/* 427 */                     Invite inv = getInvite(invInfo.getMsgId(), invInfo.getComponentId());
/* 428 */                     RecurId rid = inst.makeRecurId(inv);
/*     */                     
/*     */ 
/* 431 */                     getReplyList().modifyPartStat(resource, rid, null, resource.getName(), null, null, "DE", Boolean.valueOf(false), invite.getSeqNo(), opTime);
/*     */                     
/*     */ 
/* 434 */                     replyListUpdated = true;
/*     */                     
/*     */ 
/* 437 */                     Invite replyInv = makeReplyInvite(account, authAcct, lc, onBehalfOf, allowPrivateAccess, inv, rid, CalendarMailSender.VERB_DECLINE);
/*     */                     
/*     */ 
/* 440 */                     replyInvites.add(replyInv);
/*     */                   }
/*     */                   
/* 443 */                   if (needReplyEmail) {
/* 444 */                     ICalTimeZone tz = chooseReplyTZ(invite);
/*     */                     
/* 446 */                     String declinedInstances = getDeclinedTimesString(octxt, mbox, conflicts, invite.isAllDayEvent(), tz, lc);
/*     */                     
/* 448 */                     String msg = L10nUtil.getMessage(L10nUtil.MsgKey.calendarResourceDeclinedInstances, lc, new Object[0]) + "\r\n\r\n" + declinedInstances;
/*     */                     
/*     */ 
/* 451 */                     CalendarMailSender.sendResourceAutoReply(octxt, mbox, true, CalendarMailSender.VERB_ACCEPT, true, msg, this, invite, new Invite[] { acceptInv }, mmInv);
/*     */                     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 457 */                     String conflictingTimes = getBusyTimesString(octxt, mbox, conflicts, tz, lc, false);
/* 458 */                     msg = L10nUtil.getMessage(L10nUtil.MsgKey.calendarResourceDeclinedInstances, lc, new Object[0]) + "\r\n\r\n" + declinedInstances + "\r\n" + L10nUtil.getMessage(L10nUtil.MsgKey.calendarResourceDeclineReasonConflict, lc, new Object[0]) + "\r\n\r\n" + conflictingTimes;
/*     */                     
/*     */ 
/*     */ 
/*     */ 
/* 463 */                     CalendarMailSender.sendResourceAutoReply(octxt, mbox, true, CalendarMailSender.VERB_DECLINE, true, msg, this, invite, (Invite[])replyInvites.toArray(new Invite[0]), mmInv);
/*     */                     
/*     */ 
/*     */ 
/*     */ 
/* 468 */                     replySent = true;
/*     */ 
/*     */                   }
/*     */                   
/*     */                 }
/*     */                 
/*     */ 
/*     */               }
/*     */               else
/*     */               {
/*     */ 
/* 479 */                 partStat = "DE";
/* 480 */                 if (needReplyEmail) {
/* 481 */                   ICalTimeZone tz = chooseReplyTZ(invite);
/* 482 */                   String msg = L10nUtil.getMessage(L10nUtil.MsgKey.calendarResourceDeclineReasonConflict, lc, new Object[0]) + "\r\n\r\n" + getBusyTimesString(octxt, mbox, conflicts, tz, lc, checkResult.hasMoreConflicts());
/*     */                   
/*     */ 
/*     */ 
/* 486 */                   Invite replyInv = makeReplyInvite(account, authAcct, lc, onBehalfOf, allowPrivateAccess, invite, invite.getRecurId(), CalendarMailSender.VERB_DECLINE);
/*     */                   
/*     */ 
/* 489 */                   CalendarMailSender.sendResourceAutoReply(octxt, mbox, true, CalendarMailSender.VERB_DECLINE, false, msg, this, invite, new Invite[] { replyInv }, mmInv);
/*     */                   
/*     */ 
/*     */ 
/*     */ 
/* 494 */                   replySent = true;
/*     */                 }
/*     */               }
/*     */             }
/*     */           }
/*     */         }
/* 500 */         if ((!replySent) && ("AC".equals(partStat)) && 
/* 501 */           (needReplyEmail)) {
/* 502 */           Invite replyInv = makeReplyInvite(account, authAcct, lc, onBehalfOf, allowPrivateAccess, invite, invite.getRecurId(), CalendarMailSender.VERB_ACCEPT);
/*     */           
/*     */ 
/* 505 */           CalendarMailSender.sendResourceAutoReply(octxt, mbox, true, CalendarMailSender.VERB_ACCEPT, false, null, this, invite, new Invite[] { replyInv }, mmInv);
/*     */         }
/*     */         
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 513 */         if ("NE".equals(partStat)) {
/* 514 */           getReplyList().modifyPartStat(resource, invite.getRecurId(), null, resource.getName(), null, null, partStat, Boolean.valueOf(false), invite.getSeqNo(), opTime);
/*     */           
/*     */ 
/* 517 */           replyListUpdated = true;
/*     */         }
/* 519 */         if ((forCreate) && (replyListUpdated)) {
/* 520 */           saveMetadata();
/*     */         }
/*     */       }
/*     */     }
/* 524 */     CreateCalendarItemRecorder recorder = (CreateCalendarItemRecorder)mbox.getRedoRecorder();
/*     */     
/* 526 */     recorder.setCalendarItemPartStat(partStat);
/*     */     
/* 528 */     invite.updateMyPartStat(account, partStat);
/* 529 */     if (forCreate) {
/* 530 */       Invite defaultInvite = getDefaultInviteOrNull();
/* 531 */       if ((defaultInvite != null) && (!defaultInvite.equals(invite)) && (!partStat.equals(defaultInvite.getPartStat())))
/*     */       {
/* 533 */         defaultInvite.updateMyPartStat(account, partStat);
/* 534 */         saveMetadata();
/*     */       }
/*     */     }
/*     */     
/* 538 */     return partStat;
/*     */   }
/*     */   
/*     */ 
/*     */   private ICalTimeZone chooseReplyTZ(Invite invite)
/*     */     throws ServiceException
/*     */   {
/* 545 */     Account account = getMailbox().getAccount();
/* 546 */     Account organizer = invite.getOrganizerAccount();
/* 547 */     ICalTimeZone tz = invite.getStartTime().getTimeZone();
/* 548 */     if ((tz == null) && (invite.isAllDayEvent()))
/*     */     {
/* 550 */       tz = Util.getAccountTimeZone(account);
/* 551 */       if (tz == null) {
/* 552 */         ICalTimeZone.getUTC();
/*     */       }
/*     */     }
/* 555 */     else if ((tz == null) || (tz.sameAsUTC())) {
/* 556 */       if (organizer != null)
/*     */       {
/*     */ 
/* 559 */         tz = Util.getAccountTimeZone(organizer);
/*     */       }
/*     */       else {
/* 562 */         tz = Util.getAccountTimeZone(account);
/* 563 */         if (tz == null) {
/* 564 */           ICalTimeZone.getUTC();
/*     */         }
/*     */       }
/*     */     }
/*     */     
/*     */ 
/*     */ 
/* 571 */     return tz;
/*     */   }
/*     */   
/*     */ 
/*     */   private Invite makeReplyInvite(Account account, Account authAccount, Locale lc, boolean onBehalfOf, boolean allowPrivateAccess, Invite inv, RecurId rid, CalendarMailSender.Verb verb)
/*     */     throws ServiceException
/*     */   {
/* 578 */     boolean hidePrivate = (!inv.isPublic()) && (!allowPrivateAccess);
/*     */     String subject;
/* 580 */     String subject; if (hidePrivate) {
/* 581 */       subject = L10nUtil.getMessage(L10nUtil.MsgKey.calendarSubjectWithheld, lc, new Object[0]);
/*     */     } else
/* 583 */       subject = inv.getName();
/* 584 */     String replySubject = CalendarMailSender.getReplySubject(verb, subject, lc);
/* 585 */     ParsedDateTime ridDt = rid != null ? rid.getDt() : null;
/* 586 */     Invite replyInv = CalendarMailSender.replyToInvite(account, authAccount, onBehalfOf, allowPrivateAccess, inv, verb, replySubject, ridDt);
/*     */     
/* 588 */     return replyInv;
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/mailbox/Appointment.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */